package org.projects.graduates.domain;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang3.builder.HashCodeBuilder;

import com.dayatang.domain.AbstractEntity;
import com.dayatang.domain.QuerySettings;

/**
 * 作业分配
 * 
 * @author Administrator
 * 
 */
@Entity
@Table(name = "homework_assignments")
public class HomeworkAssignments extends AbstractEntity {

	private static final long serialVersionUID = 7948583480997744017L;

	@OneToOne
	@NotNull
	private TimeTable timeTable;

	@NotNull
	private String content;

	// 布置作业的时间
	@Temporal(TemporalType.DATE)
	private Date time;

	public int hashCode() {
		return new HashCodeBuilder(17, 37).append(this.getId()).toHashCode();
	}

	public static HomeworkAssignments findby(TimeTable tt) {
		QuerySettings<HomeworkAssignments> settings = QuerySettings.create(HomeworkAssignments.class);
		return getRepository().getSingleResult(settings.eq("timeTable", tt));
	}

	public boolean equals(Object other) {
		if (null == other) {
			return false;
		}
		if (other instanceof HomeworkAssignments) {
			HomeworkAssignments o = (HomeworkAssignments) other;
			if (o.getId() == this.getId()) {
				return true;
			}
		}
		return false;
	}

	public String toString() {
		return timeTable.getTeachDate() + " 's homework";
	}

	public TimeTable getTimeTable() {
		return timeTable;
	}

	public void setTimeTable(TimeTable timeTable) {
		this.timeTable = timeTable;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

}
